//
//  HomeSevenCollectionViewCell.m
//  CommunitySupermarketProiect
//
//  Created by 吕惠卿 on 2017/10/12.
//  Copyright © 2017年 吕惠卿. All rights reserved.
//

#import "HomeSevenCollectionViewCell.h"

@implementation HomeSevenCollectionViewCell
-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}
-(void)creatUI{
    _metreLab = [[UILabel alloc]init];
    _metreLab.textColor = [UIColor lightGrayColor];
    _metreLab.textAlignment = NSTextAlignmentRight;
    _metreLab.font = [UIFont systemFontOfSize:12.0];
    [self addSubview:_metreLab];
    [_metreLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).with.offset(-15);
        make.bottom.equalTo(self.mas_bottom).with.offset(-5);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(100);
    }];
    NSMutableAttributedString * attrubedStr = [[NSMutableAttributedString    alloc]initWithString:[NSString stringWithFormat:@"111.3km"]];
    NSTextAttachment * attach = [[NSTextAttachment alloc]init];
    attach.image = [UIImage imageNamed:@"距离"];
    //图片位置
    attach.bounds = CGRectMake(0, 0, 10, 10);
    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attach];
    //将图片放在最后一位
    [attrubedStr insertAttributedString:string atIndex:0];

    //NSTextAttachment * attach = [[NSTextAttachment alloc]init];
    self.metreLab.attributedText = attrubedStr;
    
    
    _nameLab = [[UILabel alloc]init];
    _nameLab.textAlignment = NSTextAlignmentLeft;
    _nameLab.font = [UIFont systemFontOfSize:14.0];
    [self addSubview:_nameLab];
    [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(8);
        make.right.equalTo(_metreLab.mas_left).with.offset(-2);
        make.bottom.equalTo(self.mas_bottom).with.offset(-5);
        make.height.mas_equalTo(25);
    }];
    _imageView = [[UIImageView alloc]init];
    _imageView.backgroundColor = LineColor;
    [self addSubview:_imageView];
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(3);
        make.left.equalTo(self.contentView.mas_left).with.offset(15);
        make.right.equalTo(self.contentView.mas_right).with.offset(-15);
        make.bottom.equalTo(_nameLab.mas_top).with.offset(-5);
    }];

}
@end
